﻿/// <summary>
/// jQuery Utility Plugin
/// author:hongda.yu@jrj.com.cn
///</summary>
(function ($) {
    $.utility = {

        //ellipsis
        ellipsis: function (params) {
            
            var settings = $.extend({
                selector: '.ellipsis',
                length: 20,
                char: '...'
            }, params);

            $(settings.selector).each(function (i, v) {
                var text = $(this).text(),
                    length = text.length;
                if (length > settings.length) {
                    $(this).html(text.substring(0, settings.length) + settings.char);
                }
            });
        },
        //encode & decode
        encode: function (input) {
            return $("<div/>").text(input).html();
        },
        decode: function (input) {
            return $("<div/>").html(input).text();
        },

        //get url parameter
        getPara: function (paraName) {
            var str = window.location.href;
            if (str.indexOf(paraName) != -1) {
                var pos_start = str.indexOf(paraName) + paraName.length + 1;
                var pos_end = str.indexOf("&", pos_start);
                if (pos_end == -1) {
                    return str.substring(pos_start);
                }
                else {
                    return str.substring(pos_start, pos_end)
                }
            }
            else {
                return '';
            }
        }
    }
})(jQuery);